/**
 * 
 */
package app.maker.stock.impl;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import app.maker.entity.Entree;
import app.maker.error.EntreeException;
import app.maker.stock.intf.IEntree;

/**
 * @author ronnie
 * 
 */
@Stateless(name = "daoEntree")
public class EntreeImpl implements IEntree {
	@PersistenceContext
	private EntityManager em;

	public void updateEntree(Entree entree) throws EntreeException {
		if (entree != null)
			em.merge(entree);
		else
			throw new EntreeException("Entrée non trouvée!");

	}

	public void deleteEntree(Entree entree) throws EntreeException {
		if (entree != null)
			em.remove(entree);
		else
			throw new EntreeException("Entrée non trouvée!");
	}

	public Entree getEntree(int id) throws EntreeException {
		if (id > 0)
			return em.find(Entree.class, id);
		else
			throw new EntreeException("Identifiant incorrecte!");
	}

	@SuppressWarnings("unchecked")
	public List<Entree> getAllEntree() {
		return em.createNamedQuery("Entree.findAll").getResultList();
	}

}
